﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Traceability.APP.Application.Command.Breeds;
using Traceability.APP.Application.Command.Slaughters;
using Traceability.Damoin;
using Traceability.ErrorCode;

namespace Traceability.APP.Controllers
{
    /// <summary>
    /// 屠宰
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class SlaughterController : ControllerBase
    {
        private readonly IMediator mediator;

        public SlaughterController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 获取屠宰表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Slaughter>>> GetSlaughter([FromQuery] GetSlaughterCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddSlaughter(AddSlaughterCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 屠宰修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateSlaughter(UpdateSlaughterCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取屠宰企业表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Slaughteringenterprise>>> GetSlaughteringenterprise([FromQuery] GetSlaughteringenterpriseCommand command)
        {
            try
            {
                var result = await mediator.Send(command);
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        /// <summary>
        /// 屠宰宰企新增
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<APIResult<int>> AddSlaughteringenterprise(AddSlaughteringenterpriseCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 屠宰宰企修改
        /// </summary>
        /// <param name="request">实体</param>
        /// <returns>返回任务</returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateSlaughteringenterprise(UpdateSlaughteringenterpriseCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
